package jmine.tec.script.persistent.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.UniqueConstraint;
import jmine.tec.script.persistent.dao.ScriptLanguageIdentifier;
import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.persister.annotation.NaturalKey;
import bancosys.tec.persist.persister.annotation.SystemId;

/**
 * Entidade que designa o propósito do script.
 * 
 * @author lundberg
 */
@Entity
@Table(name = "SCRIPT_LANGUAGE")
@Alias("SCRLNG")
@SequenceGenerator(name = "SEQ_SCRLNG", sequenceName = "SEQ_SCRLNG")
@Documentation("LINGUAGENS DE SCRIPTS.")
public class ScriptLanguage extends PersistableBusinessObject {

    private Long id;

    private String mnemonico;

    private String abreviacao;

    private String executorClass;

    /**
     * @return the id
     */
    @Id
    @SystemId
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SCRLNG")
    @Column(name = "COD_SCRIPT_LANGUAGE", nullable = false)
    @Documentation("CODIGO DA LINGUAGEM DE SCRIPT.")
    public Long getId() {
        return this.id;
    }

    /**
     * @return the mnemonico
     */
    @NaturalKey
    @Column(name = "MNE", nullable = false)
    @Documentation("MNEMONICO DA LINGUAGEM DE SCRIPT.")
    @UniqueConstraint(name = "AK_SCRLNG_0")
    public String getMnemonico() {
        return this.mnemonico;
    }

    /**
     * @return the abreviacao
     */
    @UniqueConstraint(name = "AK_SCRLNG_1")
    @Column(name = "ABREV", length = 4, nullable = false)
    @Documentation("ABREVIACAO DO MNEMONICO.")
    public String getAbreviacao() {
        return this.abreviacao;
    }

    /**
     * @return the executorClass
     */
    @Column(name = "EXEC_CLASSNAME", nullable = false)
    @Documentation("CLASSE DO EXECUTOR PADRAO DA LINGUAGEM.")
    public String getExecutorClass() {
        return this.executorClass;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param mnemonico the mnemonico to set
     */
    public void setMnemonico(String mnemonico) {
        this.mnemonico = mnemonico;
    }

    /**
     * @param abreviacao the abreviacao to set
     */
    public void setAbreviacao(String abreviacao) {
        this.abreviacao = abreviacao;
    }

    /**
     * @param executorClass the executorClass to set
     */
    public void setExecutorClass(String executorClass) {
        this.executorClass = executorClass;
    }

    /**
     * Verifica se esta linguagem é identificada pelo identificador dado.
     * 
     * @param identifier identifier
     * @return boolean
     */
    @Transient
    public boolean isIdentifiedBy(ScriptLanguageIdentifier identifier) {
        return this.getId().equals(identifier.getSystemId());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "ScriptLanguage: " + this.getMnemonico();
    }
}
